<script>
  import { log } from '$lib/log';
  import { simulateWorld } from '$lib/simulate';
  import { update } from '$lib/ui';
  import EntityLine from '../EntityLine.svelte';

  let { world, inventory, status, selected, select } = $props();

  const action = (e) => {
    if (status === 'idle' || status === 'active') {
      select(e);
    } else if (status === 'drop') {
      simulateWorld(world, DropAction(e));
      update();
    }
  };
</script>

<section class="inventory">
  <h3>─ Inventory ─</h3>
  {#if inventory.length === 0}
    You have nothing!
  {:else}
    {#each inventory as item}
      <EntityLine {world} onclick={() => action(item)} {selected} {item} />
    {/each}
  {/if}
</section>
